home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / fp / ifp_unix.lzh / ifp / interp / F_misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-05-23  |  3.9 KB  |  136 lines

  1.  
  2. /****** F_misc.c ******************************************************/
  3. /**                                                                  **/
  4. /**                    University of Illinois                        **/
  5. /**                                                                  **/
  6. /**                Department of Computer Science                    **/
  7. /**                                                                  **/
  8. /**   Tool: IFP                         Version: 0.5                 **/
  9. /**                                                                  **/
  10. /**   Author:  Arch D. Robison          Date:   May 1, 1985          **/
  11. /**                                                                  **/
  12. /**   Revised by: Arch D. Robison       Date:  Nov 24, 1985          **/
  13. /**                                                                  **/
  14. /**   Principal Investigators: Prof. R. H. Campbell                  **/
  15. /**                            Prof. W. J. Kubitz                    **/
  16. /**                                                                  **/
  17. /**                                                                  **/
  18. /**------------------------------------------------------------------**/
  19. /**   (C) Copyright 1987  University of Illinois Board of Trustees   **/
  20. /**                       All Rights Reserved.                       **/
  21. /**********************************************************************/
  22.  
  23. #include "struct.h"
  24. #include <stdio.h>
  25. #include "node.h"
  26. #include "string.h"
  27.  
  28. /************************** miscellaneous functions *********************/
  29.  
  30. /*
  31.  * NodeExpand
  32.  *
  33.  * Replace object with equivalent object not containing nodes.
  34.  *
  35.  * Nodes are converted to equivalent path lists.
  36.  */
  37. void NodeExpand (InOut)
  38.    register ObjectPtr InOut;
  39.    {
  40.       register ListPtr P;
  41.       register NodePtr N;
  42.  
  43.       switch (InOut->Tag) {
  44.  
  45.      case LIST:
  46.         CopyTop (&InOut->List);
  47.         for (P=InOut->List; P!=NULL; P=P->Next) NodeExpand (&P->Val);
  48.         break;
  49.  
  50.      case NODE:
  51.         N = InOut->Node;
  52.         RepTag (InOut,LIST);
  53.         InOut->List = MakePath (N);
  54.         break;
  55.       }
  56.    }
  57.  
  58. /*
  59.  * F_Def
  60.  *
  61.  * Return the object representation of a function definition.
  62.  *
  63.  * Input
  64.  *      *InOut = pathname list
  65.  *
  66.  * Output
  67.  *      *InOut = function definition representation
  68.  */
  69. int F_Def (InOut)               /* imported by Compile in C_comp.c */
  70.    register ObjectPtr InOut;
  71.    {
  72.       extern void ReadDef (), RepBool ();
  73.       register DefPtr D;
  74.  
  75.       if (InOut->Tag != LIST) FunError (ArgNotSeq,InOut);
  76.       else {
  77.      LinkPath (InOut);
  78.      if (InOut->Tag==NODE && InOut->Node->NodeType==DEF) {
  79.         D = &InOut->Node->NodeData.NodeDef;
  80.         if (D->DefCode.Tag != CODE) {
  81.            if (D->DefCode.Tag == BOTTOM) ReadDef ((NodePtr) NULL,InOut);
  82.            if (D->DefCode.Tag != BOTTOM) {
  83.           RepObject (InOut,&D->DefCode);
  84.           NodeExpand (InOut);
  85.           return;
  86.            }
  87.         }
  88.      }
  89.       }
  90.       RepBool (InOut,0);   /* function not defined */
  91.    }
  92.  
  93. /*
  94.  * F_Apply
  95.  *
  96.  * Apply a function to an object. 
  97.  *
  98.  * Input
  99.  *     InOut = <X F> where F is a function
  100.  *
  101.  * Output
  102.  *     InOut = X : F
  103.  */
  104. private int F_Apply (InOut)
  105.    ObjectPtr InOut;
  106.    {
  107.       register ListPtr P;
  108.  
  109.       /* 
  110.        * We don't want to use PairTest test here, since it would expand
  111.        * the function if its a node.  This would not affect the behavior
  112.        * at all, but would slow things down since the function must be
  113.        * converted to its node representation immediately afterwards.
  114.        */
  115.       if (InOut->Tag != LIST || 2 != ListLength (InOut->List))
  116.      FunError ("not a pair",InOut);
  117.       else {
  118.      CopyTop (&InOut->List);
  119.      P = InOut->List;
  120.      if (ApplyCheck (&P->Next->Val)) {
  121.         Apply (&P->Val,&P->Next->Val);
  122.         RepObject (InOut,&P->Val);
  123.      } else 
  124.         FunError ("invalid function",InOut);
  125.       }
  126.    }
  127.  
  128. void D_misc ()
  129.    {
  130.       (void) PrimDef (F_Apply,"apply",SysNode);
  131.       (void) PrimDef (F_Def,"def",SysNode);
  132.    }
  133.  
  134. /**************************** end of F_misc ****************************/
  135.  
  136.